#include "enemy.h"
#include <QTime>

enemy::enemy()
{
    plane.load(":/image/enemy_1.png");
    plane = plane.scaled(100,80);
    x = 100;
    y =-150;
    health = 50;
}

void enemy::choice()
{
    int n;
    do{
    QTime time= QTime::currentTime();

        qsrand(time.msec()+time.second()*1000);
        n = rand()%5;
    }while(n<=0||n>4);

        plane.load(QString(":/image/enemy_%1.png").arg(n));
}
void enemy::init()
{
    plane.load(":/image/enemy_1.png");
    plane = plane.scaled(100,80);
    x = 100;
    y =-150;
    health = 50;
    for(int a = 0;a<6;a++)
    {
        bmt[a].stop();
    }
}
void enemy::bomb()
{
    int t = 110;
    plane.load(":/image/bomb-1.png");
    bmt[0].start(t*1);
    bmt[1].start(t*2);
    bmt[2].start(t*3);
    bmt[3].start(t*4);
    bmt[4].start(t*5);
    bmt[5].start(t*6);
    for(int a = 0;a<6;a++)
    QObject::connect(bmt+a,&QTimer::timeout,[=]()
    {
        plane.load(QString(":/image/bomb-%1.png").arg(a+2));
        bmt[a].stop();
    });
}
